{% if template contains 'product' and settings.display-related-products %}

    {% assign number_of_related_products_to_show = 4 %}
    {% assign image_size = 'medium' %}
    {% assign heading = settings.related-products-title %}

    {% capture number_of_related_products_to_fetch %}{{ number_of_related_products_to_show | plus: 1 }}{% endcapture %}

    {% if collection == null or collection.handle == 'frontpage' or collection.handle == 'all' %}
        {% assign found_a_collection = false %}
        {% for c in product.collections %}
            {% if found_a_collection == false and c.handle != 'frontpage' and c.handle != 'all' %}
                {% assign found_a_collection = true %}
                {% assign collection = c %}
            {% endif %}
        {% endfor %}
    {% endif %}
    
    {% if collection.products.size > 1 %}

    <section id="related-products" class="section">
        <div class="section-title single-borders"><h1 class="accent-text">{{ settings.related-products-title }}</h1></div>
    
        <ul class="product-list clearfix">
            
            {% assign current_product_found = false %}
            {% for prod in collection.products limit: number_of_related_products_to_fetch %}{% if prod.title == product.title %}{% assign current_product_found = true %}{% else %}{% unless current_product_found == false and forloop.last %}{% include 'small-product-item' %}{% endunless %}{% endif %}{% endfor %}
            
        </ul>        
    </section>

    {% endif %}
    
{% endif %}